package com.zoo.wuhua.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import com.zoo.wuhua.entity.JpaBook;
import com.zoo.wuhua.service.BookJpaService;

/**
 * @description
 * @author zhangli7@yusys.com.cn
 * @since 2020年2月16日 上午10:42:26 v1.0
 */
@RestController
public class BookJpaController {

    @Autowired
    BookJpaService bookJpaService;

    @GetMapping("/findAll")
    public String findAll() {
        PageRequest pageable = PageRequest.of(1, 2);
        Page<JpaBook> page = bookJpaService.getJpaBookByPage(pageable);
        String result = "总记录数：" + page.getTotalElements() + "\n";
        result += "总页数：" + page.getTotalPages() + "\n";
        result += "查询结果：" + page.getContent() + "\n";
        result += "当前页数：" + (page.getNumber() + 1) + "\n";
        result += "当前页记录数：" + page.getNumberOfElements() + "\n";
        result += "每页记录数：" + page.getSize() + "\n";
        return result;
    }
}
